﻿Imports System.Data
Imports System.Data.SqlClient
Public Class TheLoaiDAO
    Shared Function loadTheLoai() As DataTable
        Dim sql As String = "select * from THELOAI"
        Dim dt As New DataTable
        dt = DataProvider.DataTable(sql)
        Return dt
    End Function

    Shared Function returnTL(ByVal tl As TheLoaiDTO) As String
        Dim cn As New SqlConnection
        cn = DataProvider.CreaConnection()
        Dim cmd As New SqlCommand("sp_tenTheLoai", cn)
        cmd.CommandType = CommandType.StoredProcedure

        Dim input As New SqlParameter("@maTL", SqlDbType.Char)
        Dim output As New SqlParameter("@tenTLoai", SqlDbType.NVarChar)

        output.Size = 30
        input.Size = 10
        input.Value = tl.maTheLoai
        output.Direction = ParameterDirection.Output

        cmd.Parameters.Add(input)
        cmd.Parameters.Add(output)

        cmd.ExecuteNonQuery()

        Dim str As String
        str = Convert.ToString(output.Value)
        cn.Close()
        Return str
    End Function

    Shared Function soLuongTL(ByVal thl As TheLoaiDTO) As Integer
        Dim cn As New SqlConnection
        cn = DataProvider.CreaConnection()
        Dim cmd As New SqlCommand("sp_soLuongTL", cn)
        cmd.CommandType = CommandType.StoredProcedure

        Dim input As New SqlParameter("@maTL", SqlDbType.Char)
        Dim output As New SqlParameter("@soluong", SqlDbType.Int)

        input.Size = 10
        input.Value = thl.maTheLoai
        output.Direction = ParameterDirection.Output

        cmd.Parameters.Add(input)
        cmd.Parameters.Add(output)

        cmd.ExecuteNonQuery()

        Dim sl As Integer
        sl = Convert.ToInt32(output.Value)
        cn.Close()
        Return sl
    End Function

    Public Shared Sub updateTheLoai(ByVal thl As TheLoaiDTO)
        thl.soLuongPhim = thl.soLuongPhim + 1
        Dim sql As String = "update THELOAI set SoLuongPhim=" + thl.soLuongPhim.ToString() + " where MaTheLoai='" + thl.maTheLoai + "'"
        DataProvider.ExcuteQuery(sql)
    End Sub
End Class
